#!/usr/bin/python3.5

# -*- coding: utf-8 -*-

def binary_search(arr,target):
    k=0
    l=0
    r = len(arr)

    while r>l:
        mid = (r+l)//2
        k+=1

        if arr[mid]>target:
            r = mid
        else:
            if mid < r-1 and arr[mid+1]<=target:
                l = mid+1
            else:
                print(mid)
                return True

    return False



if __name__ == "__main__":
    n = 100
    a = [1,2,2,3,3,3,3,3,4,5,6,7,9]
    target = 8
    print(binary_search(a,target))
